<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="18" :lg="7" :md="8" :sm="24">
            <!-- 仓库的详情 -->
            <div style="width: 100%">
              <p style="font-size: 18px;color: #2d2d2d;font-weight: bolder;float: left">{{cangku_name}}</p>
              <p style="font-size: 13px;color: #656363;float: left;margin-left: 14px;margin-top: 3px">序号：{{cangku_numbers}}</p>
              <p style="font-size: 13px;color: #656363;float: left;margin-left: 12px;margin-top: 3px">编号：{{cangku_code}}</p>
              <p style="font-size: 13px;color: #656363;float: left;margin-left: 12px;margin-top: 3px">新增时间：{{cangku_addtime}}</p>
            </div>
<!--            <div style="width: 100%;overflow: hidden;margin-bottom: 10px">-->
<!--              <p style="font-size: 13px;color: #656363;float: left;">联系人：{{cangku_ren}}</p>-->
<!--              <p style="font-size: 13px;color: #656363;float: left;margin-left: 12px;">联系电话：{{cangku_phone}}</p>-->
<!--              <p style="font-size: 13px;color: #656363;float: left;margin-left: 12px;">仓库地址：{{cangku_address}}</p>-->
<!--            </div>-->
          </a-col>

          <a-button type="primary" @click="increase_data(0)" icon="plus" style="color: #F9D532;width: 110px;height: 36px;background: #333333;border-style: none;float: right;margin-right: 16px;">新增</a-button>
        </a-row>
      </a-form>
    </div>


    <div style="background: #f2f2f2;height: 10px;width: auto;margin-top: 10px;margin-bottom: 30px;"></div>


    <div>
      <div style="border: none;background-color: #ffffff;padding-bottom: 28px;">
        <span style="font-size: 16px;float: left;color:#000000;font-weight: bold;margin-bottom: 10px">货架列表</span>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" style="margin-top: -20px;">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.img)" icon="img"/>
          </div>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <div align="center" style="align-content: center;margin-left: 20px;">
          <a @click="set_reservoir(record.id)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">查看库位</a>
          <a @click="increase_data(record)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">编辑</a>

          <a-menu-item style="float: left;margin-left: 10px;" v-if="record.status==0">
             <a-popconfirm title="确定停用该库区吗?" @confirm="() => edit_data_status(record.id,1)">
                  <a style="font-size: 14px;color: #bd0741;">停用</a>
                </a-popconfirm>
          </a-menu-item>

           <a-menu-item style="margin-left: 10px;float: left;margin-top: 0px;" v-if="record.status==1">
            <a-popconfirm title="确定启用该库区吗?" @confirm="() => edit_data_status(record.id,0)">
              <a style="font-size: 14px;color: #d29328;">启用</a>
            </a-popconfirm>
          </a-menu-item>

             <a-menu-item style="margin-left: 10px;float: left;margin-top: 0px;" v-if="record.status==1">
            <a-popconfirm title="确定删除该库区吗?" @confirm="() => edit_data_status(record.id,2)">
              <a style="font-size: 14px;color: #d29328;">删除</a>
            </a-popconfirm>
          </a-menu-item>

          </div>
        </span>
      </a-table>
    </div>

    <AddShelvesModule ref="modalForm" @ok="modalFormOk"></AddShelvesModule>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {getAction,putAction,getFileAccessHttpUrl,httpAction} from '@/api/manage';
  import JDate from '@/components/jeecg/JDate.vue'
  import '@/assets/less/TableExpand.less'
  import AddShelvesModule from './modules/AddShelvesModule'

  export default {
    name: "categoryinfo",
    mixins:[JeecgListMixin],
    components: {
      JDate,
      AddShelvesModule
    },
    data () {
      return {
        description: 'categoryinfo管理页面',
        tabs: 1,//切换框
        cangku_name:'',
        cangku_code:'',
        cangku_numbers:'',
        cangku_addtime:'',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'货架名称',
            align:"center",
            dataIndex: 'shelvesName'
          },
          {
            title:'货架编号',
            align:"center",
            dataIndex: 'shelvesCode'
          },
          {
            title:'添加时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'层数',
            align:"center",
            dataIndex: 'layer'
          },
          {
            title:'列数',
            align:"center",
            dataIndex: 'columns'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status',
            customRender:function (text) {
              if(text=='0'){
                return "启用中"
              }else {
                return "已停用"
              }
            }
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/location/configuration/ShelvesPagelist?topId="+this.$route.query.kuqu_id,
          edit_cate_staus: "/location/configuration/change_Shelves_status",
          cangku_detail:"/location/configuration/query_reservoirById"
        }
      }
    },
    created(){
      this.show_cangkuDetail();//查询仓库信息
    },
    methods: {
      getAvatarView: function (avatar) {
        return getFileAccessHttpUrl(avatar)
      },
      show_cangkuDetail(){//查询仓库详情
        let params = {id:this.$route.query.kuqu_id};
        getAction(this.url.cangku_detail,params).then((res)=>{
          if(res.success){
            this.cangku_name = res.result.reservoirName;
            this.cangku_code = res.result.reservoirCode;
            this.cangku_numbers = res.result.numbers;
            this.cangku_addtime = res.result.createTime;
          }
        });
      },
      increase_data(record) {
        if(record=='0'){
          this.$refs.modalForm.edit(record);
          this.$refs.modalForm.title = "新增货架";
          this.$refs.modalForm.disableSubmit = true;
        }else {
          this.$refs.modalForm.edit(record);
          this.$refs.modalForm.title = "编辑货架";
          this.$refs.modalForm.disableSubmit = true;
        }
      },
      set_reservoir(cangku_id){//查看库位
        this.$router.push({path:'/kuwei/number',query: {huojia_id:cangku_id}})
      },
      edit_data_status(id,status){//修改状态
        let params = {id:id,status:status};
        httpAction(this.url.edit_cate_staus,params,"put").then((res)=>{
          if(res.success){
            this.$message.success(res.message);
            this.loadData();
          }else {
            this.$message.error(res.message);
          }
        });
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>